package com.bootdo.collection.utils;

import com.bootdo.collection.domain.SourceStationDO;
import com.bootdo.collection.service.SourceStationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;

@Component
public class RecursionUtil {
    @Autowired
    private SourceStationService sourceStationService;
    /**
     * 递归函数，只要得到的sourcetaionDO的type不等于1，则说明还不是站点,则递归直到找到该栏目的站点
     * @param sourceStationDO
     */
    public SourceStationDO recursion(SourceStationDO sourceStationDO){
        if(sourceStationDO.getType() != 1) {
            sourceStationDO = sourceStationService.get(sourceStationDO.getParentId());
            return recursion(sourceStationDO);
        }
        return sourceStationDO;
    }

    public List<Integer> recursion1(SourceStationDO sourceStationDO,List<Integer> list){
        list.add(sourceStationDO.getId());
        if(sourceStationDO.getType() != 1) {
            sourceStationDO = sourceStationService.get(sourceStationDO.getParentId());
            recursion1(sourceStationDO,list);
        }
        return list;
    }
}
